package format3

import (
	"encoding/json"
	"math"
	"regexp"
	"strconv"
	"strings"
)

/**
[]f1 [总场胜率差,总场平率差,总场负率差]
[]f2 [近场胜率差,近场平率差,近场负率差]
[]f3 [主队主场胜率,客队客场胜率]
*/

func leagueData(text string) (bool, [][]float64) {

	s := strings.Split(text, "$$$$")

	ll := strings.Split(s[0], "$$")

	if len(ll) < 2 || !strings.Contains(ll[0], "^") || !strings.Contains(ll[1], "^") {
		return false, nil
	}

	home := strings.Split(ll[0], "!")

	guest := strings.Split(ll[1], "!")
	//总数据
	a1 := strings.Split(home[0], "^")
	a2 := strings.Split(guest[0], "^")

	//近场数据
	b1 := strings.Split(home[3], "^")
	b2 := strings.Split(guest[3], "^")

	//主队主场数据，客队客场数据
	c1 := strings.Split(home[1], "^")
	c2 := strings.Split(guest[2], "^")

	//总场数
	ta1, _ := strconv.ParseFloat(a1[1], 64)
	ta2, _ := strconv.ParseFloat(a2[1], 64)

	//胜场数
	win1, _ := strconv.ParseFloat(a1[2], 64)
	win2, _ := strconv.ParseFloat(a2[2], 64)

	//平场数
	fit1, _ := strconv.ParseFloat(a1[3], 64)
	fit2, _ := strconv.ParseFloat(a2[3], 64)

	//负场数
	loss1, _ := strconv.ParseFloat(a1[4], 64)
	loss2, _ := strconv.ParseFloat(a2[4], 64)

	//近场胜
	last01, _ := strconv.ParseFloat(b1[2], 64)
	last02, _ := strconv.ParseFloat(b2[2], 64)
	//近场平
	last11, _ := strconv.ParseFloat(b1[3], 64)
	last12, _ := strconv.ParseFloat(b2[3], 64)
	//近场负
	last21, _ := strconv.ParseFloat(b1[4], 64)
	last22, _ := strconv.ParseFloat(b2[4], 64)

	//近场数
	tb1 := last01 + last11 + last21
	tb2 := last02 + last12 + last22

	//主（客）场数
	tc1, _ := strconv.ParseFloat(c1[1], 64)
	tc2, _ := strconv.ParseFloat(c2[1], 64)

	//计算进球、失球差
	wa1, _ := strconv.ParseFloat(a1[5], 64)
	wa2, _ := strconv.ParseFloat(a2[5], 64)
	la1, _ := strconv.ParseFloat(a1[6], 64)
	la2, _ := strconv.ParseFloat(a2[6], 64)

	wb1, _ := strconv.ParseFloat(b1[5], 64)
	wb2, _ := strconv.ParseFloat(b2[5], 64)
	lb1, _ := strconv.ParseFloat(b1[6], 64)
	lb2, _ := strconv.ParseFloat(b2[6], 64)

	wc1, _ := strconv.ParseFloat(c1[5], 64)
	wc2, _ := strconv.ParseFloat(c2[5], 64)
	lc1, _ := strconv.ParseFloat(c1[6], 64)
	lc2, _ := strconv.ParseFloat(c2[6], 64)

	f1 := float64(-9999)
	f2 := float64(-9999)
	f3 := float64(-9999)
	f4 := float64(-9999)
	f5 := float64(-9999)
	f6 := float64(-9999)
	if ta1 > 0 && ta2 > 0 {
		f1 = wa1/ta1 - wa2/ta2
		f2 = la1/ta1 - la2/ta2
	}
	if tb1 > 0 && tb2 > 0 {
		f3 = wb1/tb1 - wb2/tb2
		f4 = lb1/tb1 - lb2/tb2
	}
	if tc1 > 0 && tc2 > 0 {
		f5 = wc1/tc1 - wc2/tc2
		f6 = lc1/tc1 - lc2/tc2
	}
	ff1 := []float64{
		f1,
		f2,
		f3,
		f4,
		f5,
		f6,
	}
	//总场胜率
	ff2 := []float64{win1 / (ta1 * 1), win2 / (ta2 * 1)}
	//近场胜率
	ff3 := []float64{last01 / (tb1 * 1), last02 / (tb2 * 1)}

	//总场平率差
	ff4 := []float64{fit1 / (ta1 * 1), fit2 / (ta2 * 1)}
	//近场平率差
	ff5 := []float64{last11 / (tb1 * 1), last12 / (tb2 * 1)}

	//总场负率差
	ff6 := []float64{loss1 / (ta1 * 1), loss2 / (ta2 * 1)}
	//近场负率差
	ff7 := []float64{last21 / (tb1 * 1), last22 / (tb2 * 1)}

	//主队主场胜率
	pc1, _ := strconv.ParseFloat(strings.Replace(c1[9], "%", "", -1), 64)
	//客队客场胜率
	pc2, _ := strconv.ParseFloat(strings.Replace(c2[9], "%", "", -1), 64)

	ff8 := []float64{pc1 / 100, pc2 / 100}

	//排名
	rank1, _ := strconv.ParseFloat(a1[8], 64)
	rank2, _ := strconv.ParseFloat(a2[8], 64)

	ff9 := []float64{rank1-rank2}

	return true, [][]float64{
		ff1, ff2, ff3, ff4, ff5, ff6, ff7, ff8, ff9,
	}
}

/**
交战数据
[]f 近1，近3，近6
*/
func betData(startAt string, t1 string, t2 string, text string) (bool, [][]float64) {
	reg, _ := regexp.Compile("\\[[\\S\\s]+?]")
	//主队
	t1 = reg.ReplaceAllString(t1, "")
	//客队
	t2 = reg.ReplaceAllString(t2, "")
	s := strings.Split(text, "$$$$")

	m := strings.Split(s[1], "$$")
	//最近交锋数据处理
	bet := strings.Split(m[0], "!")
	w := float64(0)
	l := float64(0)
	i := float64(0)
	pa := float64(0)
	pb := float64(0)
	pc := float64(0)

	w1 := float64(-9999)
	l1 := float64(-9999)
	w3 := float64(-9999)
	l3 := float64(-9999)
	w6 := float64(-9999)
	l6 := float64(-9999)
	for _, v := range bet {
		//只统计近6数据
		if i > 5 {
			break
		}
		slice := strings.Split(v, "^")
		if v == "" {
			continue
		}

		ta := slice[2]
		sa, _ := strconv.ParseFloat(slice[4], 64)
		sb, _ := strconv.ParseFloat(slice[5], 64)
		if strings.Index(ta, t1) >= 0 {
			if sa > sb {
				//赢
				w = w + sa - sb
				pa++
			}
			if sa == sb {
				pb++
			}
			if sa < sb {
				l = l + sb - sa
				pc++
			}
		} else {

			if sa < sb {
				w = w + sb - sa
				pa++
			}
			if sa == sb {
				pb++
			}
			if sa > sb {
				l = l + sa - sb
				pc++
			}
		}
		if i == 0 {
			w1 = pa
			l1 = pc
		}
		if i == 2 {
			w3 = pa / float64(3)
			l3 = pc / float64(3)
		}
		if i == 5 {
			w6 = pa / float64(6)
			l6 = pc / float64(6)
		}
		i++
	}

	if i < 3 {
		return false, nil
	}
	return true, [][]float64{
		[]float64{w1, l1},
		[]float64{w3, l3},
		[]float64{w6, l6},
		[]float64{
			w/(i),
			l/(i),
		},
	}
}

/**
最近比赛胜平负情况
*/
func lastMatchWinData(league string, t1 string, t2 string, text string) (bool, [][]float64) {

	reg, _ := regexp.Compile("\\[[\\S\\s]+?]")
	//主队
	t1 = reg.ReplaceAllString(t1, "")
	//客队
	t2 = reg.ReplaceAllString(t2, "")
	s := strings.Split(text, "BaseInfo")[1]
	jsonString := "{\"BaseInfo" + s
	data := make(map[string]interface{})
	json.Unmarshal([]byte(jsonString), &data)
	nearInfo := data["NearInfo"].(map[string]interface{})
	guestInfo := nearInfo["GuestInfo"].([]interface{})
	homeInfo := nearInfo["HomeInfo"].([]interface{})

	wa1 := float64(-9999)
	wa3 := float64(-9999)
	wa5 := float64(-9999)
	wa10 := float64(-9999)

	pa1 := float64(-9999)
	pa3 := float64(-9999)
	pa5 := float64(-9999)
	pa10 := float64(-9999)

	la1 := float64(-9999)
	la3 := float64(-9999)
	la5 := float64(-9999)
	la10 := float64(-9999)

	w1 := float64(0)
	p1 := float64(0)
	l1 := float64(0)
	s1 := float64(0)

	for _, v := range homeInfo {
		d := v.(map[string]interface{})
		if d["SclassName"] != league {
			//continue
		}
		isHome := false
		if strings.Index(d["HomeTeam"].(string), t1) >= 0 {
			isHome = true
		}
		ff := d["HomeScore"].(float64) - d["GuestScore"].(float64)
		if (isHome && ff < 0) || (!isHome && ff > 0) {
			//输
			l1++
		} else if ff == 0 {
			//平
			p1++
		} else {
			//赢
			w1++
		}
		if s1 == 0 {
			//最近一场
			wa1 = w1
			pa1 = p1
			la1 = l1
		}
		if s1 == 2 {
			//最近三场
			wa3 = w1 / 3
			la3 = l1 / 3
			pa3 = p1 / 3
		}
		if s1 == 4 {
			//最近五场
			wa5 = w1 / 5
			la5 = l1 / 5
			pa5 = p1 / 5
		}
		if s1 == 9 {
			//最近10场
			wa10 = w1 / 10
			la10 = l1 / 10
			pa10 = p1 / 10
		}
		s1++
	}
	wb1 := float64(-9999)
	wb3 := float64(-9999)
	wb5 := float64(-9999)
	wb10 := float64(-9999)

	pb1 := float64(-9999)
	pb3 := float64(-9999)
	pb5 := float64(-9999)
	pb10 := float64(-9999)

	lb1 := float64(-9999)
	lb3 := float64(-9999)
	lb5 := float64(-9999)
	lb10 := float64(-9999)

	w2 := float64(0)
	p2 := float64(0)
	l2 := float64(0)
	s2 := float64(0)

	for _, v := range guestInfo {

		d := v.(map[string]interface{})
		if d["SclassName"] != league {
			//continue
		}
		isHome := false
		if strings.Index(d["HomeTeam"].(string), t2) >= 0 {
			isHome = true
		}
		ff := d["HomeScore"].(float64) - d["GuestScore"].(float64)
		if (isHome && ff < 0) || (!isHome && ff > 0) {
			//输
			l2++
		} else if ff == 0 {
			//平
			p2++
		} else {
			//赢
			w2++
		}
		if s2 == 0 {
			//最近一场
			wb1 = w2
			lb1 = l2
		}
		if s2 == 2 {
			//最近三场
			wb3 = w2 / 3
			lb3 = l2 / 3
			pb3 = p2 / 3
		}
		if s2 == 4 {
			//最近五场
			wb5 = w2 / 5
			lb5 = l2 / 5
			pb5 = p2 / 5
		}
		if s2 == 9 {
			//最近10场
			wb10 = w2 / 10
			lb10 = l2 / 10
			pb10 = p2 / 10
		}
		s2++
	}
	if s1 == 0 || s2 == 0 {
		return false, nil
	}

	return true, [][]float64{
		[]float64{wa1, la1, pa1, wb1, lb1, pb1},
		[]float64{wa3, la3, pa3, wb3, lb3, pb3},
		[]float64{wa5, la5, pa5, wb5, lb5, pb5},
		[]float64{wa10, la10, pa10, wb10, lb10, pb10},
	}
}

/**
最近比赛的得、失球情况
*/
func lastMatchData(league string, t1 string, t2 string, text string) (bool, [][]float64) {

	reg, _ := regexp.Compile("\\[[\\S\\s]+?]")
	//主队
	t1 = reg.ReplaceAllString(t1, "")
	//客队
	t2 = reg.ReplaceAllString(t2, "")
	s := strings.Split(text, "BaseInfo")[1]
	jsonString := "{\"BaseInfo" + s
	data := make(map[string]interface{})
	json.Unmarshal([]byte(jsonString), &data)
	nearInfo := data["NearInfo"].(map[string]interface{})
	guestInfo := nearInfo["GuestInfo"].([]interface{})
	homeInfo := nearInfo["HomeInfo"].([]interface{})

	wa1 := float64(-9999)
	wa3 := float64(-9999)
	wa5 := float64(-9999)
	wa10 := float64(-9999)

	la1 := float64(-9999)
	la3 := float64(-9999)
	la5 := float64(-9999)
	la10 := float64(-9999)

	w1 := float64(0)
	l1 := float64(0)
	s1 := float64(0)

	for _, v := range homeInfo {
		d := v.(map[string]interface{})
		if d["SclassName"] != league {
			//continue
		}
		isHome := false
		if strings.Index(d["HomeTeam"].(string), t1) >= 0 {
			isHome = true
		}
		ff := d["HomeScore"].(float64) - d["GuestScore"].(float64)
		if (isHome && ff < 0) || (!isHome && ff > 0) {
			//输
			l1 = l1 + math.Abs(ff)
		} else if ff == 0 {
			//平
		} else {
			//赢
			w1 = w1 + math.Abs(ff)
		}
		if s1 == 0 {
			//最近一场
			wa1 = w1 / 1
			la1 = l1 / 1
		}
		if s1 == 2 {
			//最近三场
			wa3 = w1 / 3
			la3 = l1 / 3
		}
		if s1 == 4 {
			//最近五场
			wa5 = w1 / 5
			la5 = l1 / 5
		}
		if s1 == 9 {
			//最近10场
			wa10 = w1 / 10
			la10 = l1 / 10
		}
		s1++
	}
	wb1 := float64(-9999)
	wb3 := float64(-9999)
	wb5 := float64(-9999)
	wb10 := float64(-9999)

	lb1 := float64(-9999)
	lb3 := float64(-9999)
	lb5 := float64(-9999)
	lb10 := float64(-9999)

	w2 := float64(0)
	l2 := float64(0)
	s2 := float64(0)

	for _, v := range guestInfo {

		d := v.(map[string]interface{})
		if d["SclassName"] != league {
			//continue
		}
		isHome := false
		if strings.Index(d["HomeTeam"].(string), t2) >= 0 {
			isHome = true
		}
		ff := d["HomeScore"].(float64) - d["GuestScore"].(float64)
		if (isHome && ff < 0) || (!isHome && ff > 0) {
			//输
			l2 = l2 + math.Abs(ff)
		} else if ff == 0 {
			//平

		} else {
			//赢
			w2 = w2 + math.Abs(ff)
		}
		if s2 == 0 {
			//最近一场
			wb1 = w2 / 1
			lb1 = l2 / 1
		}
		if s2 == 2 {
			//最近三场
			wb3 = w2 / 3
			lb3 = l2 / 3
		}
		if s2 == 4 {
			//最近五场
			wb5 = w2 / 5
			lb5 = l2 / 5
		}
		if s2 == 9 {
			//最近10场
			wb10 = w2 / 10
			lb10 = l2 / 10
		}
		s2++
	}
	if s1 == 0 || s2 == 0 {
		return false, nil
	}

	return true, [][]float64{
		//近1
		[]float64{wa1, la1, wb1, lb1},
		[]float64{wa3, la3, wb3, lb3},
		[]float64{wa5, la5, wb5, lb5},
		[]float64{wa10, la10, wb10, lb10},
		//总
		[]float64{w1 / (s1 * 1), l1 / (s1 * 1), w2 / (s2 * 1), l2 / (s2 * 1)},
	}
}
func sameLeagueLastMatchData(league string, t1 string, t2 string, text string) (bool, [][]float64) {

	reg, _ := regexp.Compile("\\[[\\S\\s]+?]")
	//主队
	t1 = reg.ReplaceAllString(t1, "")
	//客队
	t2 = reg.ReplaceAllString(t2, "")

	s := strings.Split(text, "BaseInfo")[1]
	jsonString := "{\"BaseInfo" + s
	data := make(map[string]interface{})
	json.Unmarshal([]byte(jsonString), &data)
	nearInfo := data["NearInfo"].(map[string]interface{})
	guestInfo := nearInfo["GuestInfo"].([]interface{})
	homeInfo := nearInfo["HomeInfo"].([]interface{})

	wa1 := float64(-9999)
	wa3 := float64(-9999)
	wa5 := float64(-9999)
	wa10 := float64(-9999)

	la1 := float64(-9999)
	la3 := float64(-9999)
	la5 := float64(-9999)
	la10 := float64(-9999)

	w1 := float64(0)
	l1 := float64(0)
	s1 := float64(0)

	for _, v := range homeInfo {
		d := v.(map[string]interface{})
		if d["SclassName"] != league {
			continue
		}
		isHome := false
		if strings.Index(d["HomeTeam"].(string), t1) >= 0 {
			isHome = true
		}
		ff := d["HomeScore"].(float64) - d["GuestScore"].(float64)
		if (isHome && ff < 0) || (!isHome && ff > 0) {
			//输
			l1 = l1 + math.Abs(ff)
		} else if ff == 0 {
			//平
		} else {
			//赢
			w1 = w1 + math.Abs(ff)
		}
		if s1 == 0 {
			//最近一场
			wa1 = w1 / 1
			la1 = l1 / 1
		}
		if s1 == 2 {
			//最近三场
			wa3 = w1 / 3
			la3 = l1 / 3
		}
		if s1 == 4 {
			//最近五场
			wa5 = w1 / 5
			la5 = l1 / 5
		}
		if s1 == 9 {
			//最近10场
			wa10 = w1 / 10
			la10 = l1 / 10
		}
		s1++
	}
	wb1 := float64(-9999)
	wb3 := float64(-9999)
	wb5 := float64(-9999)
	wb10 := float64(-9999)

	lb1 := float64(-9999)
	lb3 := float64(-9999)
	lb5 := float64(-9999)
	lb10 := float64(-9999)

	w2 := float64(0)
	l2 := float64(0)
	s2 := float64(0)

	for _, v := range guestInfo {

		d := v.(map[string]interface{})
		if d["SclassName"] != league {
			continue
		}
		isHome := false
		if strings.Index(d["HomeTeam"].(string), t2) >= 0 {
			isHome = true
		}
		ff := d["HomeScore"].(float64) - d["GuestScore"].(float64)
		if (isHome && ff < 0) || (!isHome && ff > 0) {
			//输
			l2 = l2 + math.Abs(ff)
		} else if ff == 0 {
			//平

		} else {
			//赢
			w2 = w2 + math.Abs(ff)
		}
		if s2 == 0 {
			//最近一场
			wb1 = w2 / 1
			lb1 = l2 / 1
		}
		if s2 == 2 {
			//最近三场
			wb3 = w2 / 3
			lb3 = l2 / 3
		}
		if s2 == 4 {
			//最近五场
			wb5 = w2 / 5
			lb5 = l2 / 5
		}
		if s2 == 9 {
			//最近10场
			wb10 = w2 / 10
			lb10 = l2 / 10
		}
		s2++
	}
	if s1 == 0 || s2 == 0 {
		return false, nil
	}

	return true, [][]float64{
		//近1
		[]float64{wa1, la1, wb1, lb1},
		[]float64{wa3, la3, wb3, lb3},
		[]float64{wa5, la5, wb5, lb5},
		[]float64{wa10, la10, wb10, lb10},
		//总
		[]float64{w1 / (s1 * 1), l1 / (s1 * 1), w2 / (s2 * 1), l2 / (s2 * 1)},
	}
}

/*
进球能力统计，场进球占比情况。大致避免A队赢的都是弱队，B队输的都是强队造成的A弱于B的不客观描述
*/
func sameLeagueLastMatchScoreData(league string, t1 string, t2 string, text string) (bool, [][]float64) {
	reg, _ := regexp.Compile("\\[[\\S\\s]+?]")
	//主队
	t1 = reg.ReplaceAllString(t1, "")
	//客队
	t2 = reg.ReplaceAllString(t2, "")
	s := strings.Split(text, "BaseInfo")[1]
	jsonString := "{\"BaseInfo" + s
	data := make(map[string]interface{})
	json.Unmarshal([]byte(jsonString), &data)
	nearInfo := data["NearInfo"].(map[string]interface{})
	guestInfo := nearInfo["GuestInfo"].([]interface{})
	homeInfo := nearInfo["HomeInfo"].([]interface{})

	score1 := float64(0)
	scoreAll1 := float64(0)
	s1 := float64(0)
	pa1 := float64(-9999)
	pa3 := float64(-9999)
	pa6 := float64(-9999)
	pa := float64(-9999)
	for _, v := range homeInfo {
		d := v.(map[string]interface{})
		if d["SclassName"] != league {
			continue
		}
		isHome := false
		if strings.Index(d["HomeTeam"].(string), t1) >= 0 {
			isHome = true
		}

		if isHome {
			score1 += d["HomeScore"].(float64)
		} else {
			score1 += d["GuestScore"].(float64)
		}
		scoreAll1 = scoreAll1 + d["HomeScore"].(float64) + d["GuestScore"].(float64)

		if s1 == 0 {
			//最近一场
			pa1 = score1 / scoreAll1
		}
		if s1 == 2 {
			//最近三场
			pa3 = score1 / scoreAll1
		}
		if s1 == 5 {
			//最近五场
			pa6 = score1 / scoreAll1
		}

		s1++
	}
	if scoreAll1 > 0 {
		pa = score1 / scoreAll1
	}

	score2 := float64(0)
	scoreAll2 := float64(0)
	s2 := float64(0)
	pb1 := float64(-9999)
	pb3 := float64(-9999)
	pb6 := float64(-9999)
	pb := float64(-9999)

	for _, v := range guestInfo {

		d := v.(map[string]interface{})
		if d["SclassName"] != league {
			continue
		}
		isHome := false
		if strings.Index(d["HomeTeam"].(string), t2) >= 0 {
			isHome = true
		}
		if isHome {
			score2 += d["HomeScore"].(float64)
		} else {
			score2 += d["GuestScore"].(float64)
		}
		scoreAll2 = scoreAll2 + d["HomeScore"].(float64) + d["GuestScore"].(float64)

		if s2 == 0 {
			//最近一场
			pb1 = score2 / scoreAll2
		}
		if s2 == 2 {
			//最近三场
			pb3 = score2 / scoreAll2
		}
		if s2 == 5 {
			//最近六场
			pb6 = score2 / scoreAll2
		}
		s2++
	}
	if scoreAll2 > 0 {
		pb = score2 / scoreAll2
	}

	if s1 == 0 || s2 == 0 {
		return false, nil
	}

	return true, [][]float64{
		[]float64{pa1, pb1},
		[]float64{pa3, pb3},
		[]float64{pa6, pb6},
		[]float64{pa, pb},
	}
}
func lastMatchScoreData(league string, t1 string, t2 string, text string) (bool, [][]float64) {
	reg, _ := regexp.Compile("\\[[\\S\\s]+?]")
	//主队
	t1 = reg.ReplaceAllString(t1, "")
	//客队
	t2 = reg.ReplaceAllString(t2, "")
	s := strings.Split(text, "BaseInfo")[1]
	jsonString := "{\"BaseInfo" + s
	data := make(map[string]interface{})
	json.Unmarshal([]byte(jsonString), &data)
	nearInfo := data["NearInfo"].(map[string]interface{})
	guestInfo := nearInfo["GuestInfo"].([]interface{})
	homeInfo := nearInfo["HomeInfo"].([]interface{})

	score1 := float64(0)
	scoreAll1 := float64(0)
	s1 := float64(0)
	pa1 := float64(-9999)
	pa3 := float64(-9999)
	pa6 := float64(-9999)
	pa := float64(-9999)
	for _, v := range homeInfo {
		d := v.(map[string]interface{})
		if d["SclassName"] != league {
			//continue
		}
		isHome := false
		if strings.Index(d["HomeTeam"].(string), t1) >= 0 {
			isHome = true
		}

		if isHome {
			score1 += d["HomeScore"].(float64)
		} else {
			score1 += d["GuestScore"].(float64)
		}
		scoreAll1 = scoreAll1 + d["HomeScore"].(float64) + d["GuestScore"].(float64)

		if s1 == 0 {
			//最近一场
			pa1 = score1 / scoreAll1
		}
		if s1 == 2 {
			//最近三场
			pa3 = score1 / scoreAll1
		}
		if s1 == 5 {
			//最近五场
			pa6 = score1 / scoreAll1
		}

		s1++
	}
	if scoreAll1 > 0 {
		pa = score1 / scoreAll1
	}

	score2 := float64(0)
	scoreAll2 := float64(0)
	s2 := float64(0)
	pb1 := float64(-9999)
	pb3 := float64(-9999)
	pb6 := float64(-9999)
	pb := float64(-9999)

	for _, v := range guestInfo {

		d := v.(map[string]interface{})
		if d["SclassName"] != league {
			//continue
		}
		isHome := false
		if strings.Index(d["HomeTeam"].(string), t2) >= 0 {
			isHome = true
		}
		if isHome {
			score2 += d["HomeScore"].(float64)
		} else {
			score2 += d["GuestScore"].(float64)
		}
		scoreAll2 = scoreAll2 + d["HomeScore"].(float64) + d["GuestScore"].(float64)

		if s2 == 0 {
			//最近一场
			pb1 = score2 / scoreAll2
		}
		if s2 == 2 {
			//最近三场
			pb3 = score2 / scoreAll2
		}
		if s2 == 5 {
			//最近六场
			pb6 = score2 / scoreAll2
		}
		s2++
	}
	if scoreAll2 > 0 {
		pb = score2 / scoreAll2
	}

	if s1 == 0 || s2 == 0 {
		return false, nil
	}

	return true, [][]float64{
		[]float64{pa1, pb1},
		[]float64{pa3, pb3},
		[]float64{pa6, pb6},
		[]float64{pa, pb},
	}
}

//伤停情况
func sAndT(text string) []float64 {
	hs := float64(0)
	gs := float64(0)
	ht := float64(0)
	gt := float64(0)
	if strings.Contains(text, "Home_S") {
		ss := strings.Split(text, "listAway")[1]
		sss := strings.Split(ss, "$$")[2]
		data := make(map[string]interface{})
		json.Unmarshal([]byte(sss), &data)
		homeS := data["Home_S"].([]interface{})
		guestS := data["Guest_S"].([]interface{})
		homeT := data["Home_T"].([]interface{})
		guestT := data["Guest_T"].([]interface{})

		for _, v := range homeS {
			d := v.(map[string]interface{})
			if d["Num"] != "" {
				hs++
			}
		}
		for _, v := range guestS {
			d := v.(map[string]interface{})
			if d["Num"] != "" {
				gs++
			}
		}
		for _, v := range homeT {
			d := v.(map[string]interface{})
			if d["Num"] != "" {
				ht++
			}
		}
		for _, v := range guestT {
			d := v.(map[string]interface{})
			if d["Num"] != "" {
				gt++
			}
		}

	}
	return []float64{hs, gs, ht, gt}
}
func europeData(data string) []float64 {
	slice := make([]string, 0)
	json.Unmarshal([]byte(data), &slice)
	sumA := float64(0)
	sumB := float64(0)
	sumC := float64(0)

	sumD := float64(0)
	sumE := float64(0)
	sumF := float64(0)

	for _, v := range slice {
		d := strings.Split(v, "|")
		o1, _ := strconv.ParseFloat(d[3], 64)
		o2, _ := strconv.ParseFloat(d[4], 64)
		o3, _ := strconv.ParseFloat(d[5], 64)
		o4, _ := strconv.ParseFloat(d[10], 64)
		o5, _ := strconv.ParseFloat(d[11], 64)
		o6, _ := strconv.ParseFloat(d[12], 64)
		sumA = sumA + o1
		sumB = sumB + o2
		sumC = sumC + o3

		sumD = sumD + o4
		sumE = sumE + o5
		sumF = sumF + o6
	}
	size := float64(len(slice))
	return []float64{sumA / size, sumB / size, sumC / size, sumD / size, sumE / size, sumF / size}
}

func FormatData(id string, league string, startAt string, t1 string, t2 string, text string,europe string) (bool, [][]float64) {
	b, data := leagueData(text)

	if !b {
		return false, nil
	}

	b0, data0 := betData(startAt, t1, t2, text)

	if !b0 {
		return false, nil
	}
	/*b1,data1:=lastMatchWinData(league, t1, t2, text)

	if !b1 {
		return false, nil
	}*/
	b2, data2 := lastMatchData(league, t1, t2, text)
	if !b2 {
		return false, nil
	}

	b3, data3 := sameLeagueLastMatchData(league, t1, t2, text)
	if !b3 {
		return false, nil
	}
	/*b4, data4 := sameLeagueLastMatchScoreData(league, t1, t2, text)
	if !b4 {
		return false, nil
	}
	b5, data5 := lastMatchScoreData(league, t1, t2, text)
	if !b5 {
		return false, nil
	}*/
	dataEurope:=europeData(europe)

	d := [][]float64{
		dataEurope,
		data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8],
		data0[0],data0[1],data0[2],data0[3],
		//data1[0], data1[1], data1[2], data1[3],
		data2[0], data2[1], data2[2], data2[3], data2[4],
		data3[0], data3[1], data3[2], data3[3], data3[4],
		//data4[0], data4[1], data4[2], data4[3],
		//data5[0], data5[1], data5[2], data5[3],
	}

	return true, d
}
